Page({
  data: {
    curring:-1,
    detail: [
      {
        id: '1', title: ' 在基带传输中采用的编码方式有',answer:'1',array: [
          { name: '曼彻斯特编码', usname: false }, { name: '正交幅度相位调制法', usname: false },
          { name: 'FSK', usname: false }, { name: '移相键控法', usname: false },
        ]
      },
      {
        id: '2', title: '对等层之间的通信使用的是', answer: '3', array: [
          { name: '接口', usname: false }, { name: '服务', usname: false },
          { name: '协议', usname: false }, { name: '以上三者都是', usname: false },
        ]
      },
      {
        id: '3', title: '在OSI/RM中，完成路径选择功能的是', answer: '2', array: [
          { name: '物理层', usname: false }, { name: '网络层', usname: false },
          { name: '会话层', usname: false }, { name: '应用层', usname: false },
        ]
      },
      {
        id: '4', title: '计算机网络各层次结构模型及其协议的集合称为', answer: '3',  array: [
          { name: '互联参考模型', usname: false }, { name: '网络概念框架', usname: false },
          { name: '网络体系结构', usname: false }, { name: '网络结构描述', usname: false },
        ]
      },
      {
        id: '5', title: '广域网覆盖的地理范围从几十千米到几千千米，它的通信子网主要使用', answer: '2', array: [
          { name: '报文交换', usname: false }, { name: '分组交换', usname: false },
          { name: '文件交换', usname: false }, { name: '电路交换', usname: false },
        ]
      },
      {
        id: '6', title: 'OSI模型的()层负责产生和检测电压以便收发携载数据的信号', answer: '4', array: [
          { name: '传输', usname: false }, { name: '网络', usname: false },
          { name: '数据链路', usname: false }, { name: '物理', usname: false },
        ]
      },
      {
        id: '7', title: '下列协议中，运行在应用层的是', answer: '4', array: [
          { name: 'IP', usname: false }, { name: 'ARP', usname: false },
          { name: 'TCP', usname: false }, { name: 'DNS', usname: false },
        ]
      },
      {
        id: '8', title: 'MAC地址通常存储在计算机的', answer: '1', array: [
          { name: '网卡上', usname: false }, { name: '内存中', usname: false },
          { name: '高速缓存中', usname: false }, { name: '硬盘上', usname: false },
        ]
      },
      {
        id: '9', title: '数据链路层传输的PDU是', answer: '3', array: [
          { name: '比特流', usname: false }, { name: '字节', usname: false },
          { name: '数据帧', usname: false }, { name: '分组', usname: false },
        ]
      },
      {
        id: '10', title: '以集线器为核心创建的网络，其物理拓扑结构是', answer: '1', array: [
          { name: '星型', usname: false }, { name: '总线型', usname: false },
          { name: '环型', usname: false }, { name: '网状', usname: false },
        ]
      },
    ],
    number: 0,
    answer:0,
  },
  previous:function(e){
    this.setData({
      number: this.data.number-1,
      curring: this.data.curring-1,
    })
  },
  radioChange:function(e){
    let index = e.currentTarget.dataset.index
    let id = e.currentTarget.dataset.id
    let detail = this.data.detail
    for(let i = 0;i<detail.length;i++){
      if(detail[i].id == id){
        detail[i].array[index].usname = true
        for(let j = 0;j<detail[i].array.length;j++){
          if (j != index){
            detail[i].array[j].usname = false
          }
        }
      }
    }
    this.setData({
      detail:detail
    })
  },
  nextstep:function(e){
    let detail = this.data.detail
    let number = this.data.number
    let curring = this.data.curring
    let usname = 0;
    for(let i = 0;i<detail[number].array.length;i++){
      if(!detail[number].array[i].usname){
        usname++
      }
    }
    curring++
    number++
    if (curring > 9){
      curring = -1
    }
    this.setData({
      curring: curring,
      number: number,
    })
  },
  subsic:function(e){
    let detail = this.data.detail
    let answer = 0
    let letter = ''
    for(let i = 0;i < detail.length;i++){
      for(let j = 0;j < detail[i].array.length;j++){
        if(detail[i].array[j].usname){
          letter = detail[i].answer-1
          if(letter == j){
            answer++
          }
        }
      }
    }
    wx.showToast({
      title: '答对了:' + answer + '题',
      icon: 'none',
      duration: 2000
    })
  },
})
